home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 1.iso / HENSA / MATHS / PLPLOT / PLPLOT.ZIP / examples / C / x13c.c < prev    next >
C/C++ Source or Header  |  1994-06-30  |  2KB  |  104 lines

  1. /* $Id: x13c.c,v 1.7 1994/06/30 17:57:51 mjl Exp $
  2.  * $Log: x13c.c,v $
  3.  * Revision 1.7  1994/06/30  17:57:51  mjl
  4.  * All C example programs: made another pass to eliminate warnings when using
  5.  * gcc -Wall.  Lots of cleaning up: got rid of includes of math.h or string.h
  6.  * (now included by plplot.h), eliminated redundant casts, put in more
  7.  * uniform comments, and other minor changes.
  8.  *
  9.  * Revision 1.6  1994/03/30  07:21:57  mjl
  10.  * Changes to all C example programs: special handling for malloc re: header
  11.  * files eliminated, include of stdio.h and stdlib.h eliminated (now done
  12.  * by plplot.h), include of "plplot.h" changed to <plplot.h> to enable
  13.  * simpler builds by the general user, some cleaning up also.
  14. */
  15.  
  16. /*    x13c.c
  17.  
  18.     Pie chart demo.
  19. */
  20.  
  21. #include <plplot.h>
  22.  
  23. #ifndef PI
  24. #define PI      3.141592654
  25. #endif
  26.  
  27. static char *text[] =
  28. {
  29.     "Maurice",
  30.     "Randy",
  31.     "Mark",
  32.     "Steve",
  33.     "Warner"
  34. };
  35.  
  36. /*----------------------------------------------------------------------*\
  37.  * main
  38.  *
  39.  * Does a simple pie chart.
  40. \*----------------------------------------------------------------------*/
  41.  
  42. int
  43. main(int argc, char *argv[])
  44. {
  45.     int i, j;
  46.     PLFLT dthet, theta0, theta1, theta, just, dx, dy;
  47.     static PLFLT x[500], y[500], per[5];
  48.  
  49.     per[0] = 10.;
  50.     per[1] = 32.;
  51.     per[2] = 12.;
  52.     per[3] = 30.;
  53.     per[4] = 16.;
  54.  
  55. /* Parse and process command line arguments */
  56.  
  57.     (void) plParseInternalOpts(&argc, argv, PL_PARSE_FULL);
  58.  
  59. /* Initialize plplot */
  60.  
  61.     plinit();
  62.  
  63.     plenv(0., 10., 0., 10., 1, -2);
  64.     plcol(2);
  65.  
  66.     theta0 = 0.;
  67.     dthet = 2 * PI / 500;
  68.     for (i = 0; i <= 4; i++) {
  69.     j = 0;
  70.     x[j] = 5.;
  71.     y[j++] = 5.;
  72.     theta1 = theta0 + 2 * PI * per[i] / 100.;
  73.     if (i == 4)
  74.         theta1 = 2 * PI;
  75.     for (theta = theta0; theta <= theta1; theta += dthet) {
  76.         x[j] = 5 + 3 * cos(theta);
  77.         y[j++] = 5 + 3 * sin(theta);
  78.     }
  79.     plcol(i + 1);
  80.     plpsty((i + 3) % 8 + 1);
  81.     plfill(j, x, y);
  82.     plcol(1);
  83.     plline(j, x, y);
  84.     just = (theta0 + theta1) / 2.;
  85.     dx = .25 * cos(just);
  86.     dy = .25 * sin(just);
  87.     if (just < PI / 2 || just > 3 * PI / 2) 
  88.         just = 0.;
  89.     else 
  90.         just = 1.;
  91.  
  92.     plptex((x[j / 2] + dx), (y[j / 2] + dy), 1.0, 0.0, just, text[i]);
  93.     theta0 = theta - dthet;
  94.     }
  95.     plfont(2);
  96.     plschr(0., 1.3);
  97.     plptex(5.0, 9.0, 1.0, 0.0, 0.5, "Percentage of Sales");
  98.  
  99. /* Don't forget to call PLEND to finish off! */
  100.  
  101.     plend();
  102.     exit(0);
  103. }
  104.